package com.geh.learn.stream;

import com.google.common.collect.Lists;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by gehui on 2017/3/30.
 */
public class ComparatorSort {
    public static void main(String[] args) {
        // 文件内容，读取文件内容，split，然后按照某一列排序
        // header,no
        // line1,2
        // line2,3
        // line3,5
        // line4,2
        // line5,0
        long start = System.currentTimeMillis();
        String filePath = "/Users/gehui/work/gitproject/jdk-learn/src/main/resources/TestFile.txt";
        try (Stream<String> stream = Files.lines(Paths.get(filePath))) {
            List<String> list = stream.parallel().filter(line -> !line.startsWith("header"))
                    .sorted((line1, line2) -> {
                        int no1 = Integer.parseInt(line1.split(",")[1]);
                        int no2 = Integer.parseInt(line2.split(",")[1]);
                        if (no1 > no2) {
                            return 1;
                        } else if (no1 == no2) {
                            return 0;
                        } else {
                            return -1;
                        }
                    }).collect(Collectors.toList());
            // list.forEach(System.out::println);

            List<String> s = Lists.asList("c", new String[] {"a", "b"});



        } catch (IOException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.printf("Time:{%s}", end - start);
    }
}
